package com.tensquare.sms.controller;

import com.aliyuncs.exceptions.ClientException;
import com.tensquare.sms.util.SmsUtil;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;

import java.util.Map;

/**
 * Created with IDEA
 * author:zhiXiang-Chen
 * Date:2019/3/3
 * Time:21:25
 */
@Controller
@RabbitListener(queues = "sms")
public class sendSms {
    @Autowired
    private SmsUtil smsUtil;
    @Value("${aliyun.sms.template_code}")
    private String template_code;//模板编号

    @Value("${aliyun.sms.sign_name}")
    private String sign_name;//签名


    @RabbitHandler
    public void sendSms(Map<String,String> map){
        System.out.println("手机号码是:::::;  "+map.get("mobile"));
        System.out.println(map.get("code"));

        try {
            String code = map.get("code");
            smsUtil.sendSms(map.get("mobile"),template_code,sign_name,"{\"code\":\""+code+"\"}");
        } catch (ClientException e) {
            e.printStackTrace();
        }

    }

}
